package club.hiuit.share.kuaidi100.handle;

import club.hiuit.share.kuaidi100.entity.rec.OrderNum;
import club.hiuit.share.kuaidi100.entity.rec.SendOrder;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public abstract class AbstractKuaidi100Handle implements Kuaidi100Handle{

    @Override
    public String kuaidiNum(JSONArray jsonObject) {
        log.info(jsonObject.toJSONString());
        List<OrderNum> orderNums = JSONArray.parseArray(jsonObject.toJSONString(), OrderNum.class);
        return kuaidiNum(orderNums);
    }

    @Override
    public String orderInfoModiHandle(JSONObject jsonObject) {
        log.info(jsonObject.toJSONString());
        SendOrder sendOrder = JSONObject.toJavaObject(jsonObject, SendOrder.class);
        return orderInfoModiHandle(sendOrder);
    }

    @Override
    public String send(JSONObject jsonObject) {
        log.info(jsonObject.toJSONString());
        SendOrder sendOrder = JSONObject.toJavaObject(jsonObject, SendOrder.class);
        return send(sendOrder);
    }

    @Override
    public String kuaidiDefault(JSONObject jsonObject) {
        log.info(jsonObject.toJSONString());
        return null;
    }

    @Override
    public String errorSign(JSONObject jsonObject) {
        log.info(jsonObject.toJSONString());
        return null;
    }

    @Override
    public String expressInformation(JSONObject jsonObject){
        log.info(jsonObject.toJSONString());
        return null;
    };

    protected abstract String send(SendOrder sendOrder);

    protected abstract String orderInfoModiHandle(SendOrder sendOrder);

    protected abstract String kuaidiNum(List<OrderNum> orderNums);
}
